class Solution {
public:
    int removeDuplicates(int A[], int n) {
        if (n<=2) return n;
        int ret=2;
        for (int i=2;i<n;i++)
            if (A[ret-2]!=A[i]) A[ret++]=A[i];
        return ret;
    }
};
